<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
// hard line break with BiDi
const isMac = navigator.platform.indexOf('Mac') === 0;
const kBehaviors = window.internals ? ['mac', 'win'] : isMac ? ['mac'] : ['win'];
for (const behavior of kBehaviors) {
  if (window.internals) {
    internals.settings.setEditingBehavior(behavior);
    internals.settings.setSelectTrailingWhitespaceEnabled(behavior !== 'mac');
  }

selection_test(
  '<div contenteditable dir="ltr">|\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">^\u05D0\u05D1\u05D2| abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>'
      : '<div contenteditable dir="ltr">^\u05D0\u05D1\u05D2 |abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-0 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0|\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0^\u05D1\u05D2| abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0^\u05D1\u05D2 |abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-1 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1|\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1^\u05D2| abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1^\u05D2 |abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-2 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2| abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2^ abc| \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2^ |abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-3 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 |abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 ^abc| \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 ^abc |\u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-4 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 a|bc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 a^bc| \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 a^bc |\u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-5 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 ab|c \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 ab^c| \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 ab^c |\u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-6 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc| \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc^ \u05D3\u05D4\u05D5|<br>edf \u05D6\u05D7\u05D8 abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc^ |\u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-7 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc |\u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc ^\u05D3\u05D4\u05D5|<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-8 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3|\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3^\u05D4\u05D5|<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-9 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4|\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4^\u05D5|<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-10 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>|edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>^edf| \u05D6\u05D7\u05D8 abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>^edf |\u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-11 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>e|df \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>e^df| \u05D6\u05D7\u05D8 abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>e^df |\u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-12 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>ed|f \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>ed^f| \u05D6\u05D7\u05D8 abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>ed^f |\u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-13 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf| \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf^ \u05D6\u05D7\u05D8| abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf^ |\u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-14 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf |\u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf ^\u05D6\u05D7\u05D8| abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf ^\u05D6\u05D7\u05D8 |abrebg</div>',
  `${behavior} 20-15 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6|\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6^\u05D7\u05D8| abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6^\u05D7\u05D8 |abrebg</div>',
  `${behavior} 20-16 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7|\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7^\u05D8| abrebg</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7^\u05D8 |abrebg</div>',
  `${behavior} 20-17 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8| abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8^ abrebg|</div>'
      : '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8^ |abrebg</div>',
  `${behavior} 20-18 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 |abrebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 ^abrebg|</div>',
  `${behavior} 20-19 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 a|brebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 a^brebg|</div>',
  `${behavior} 20-20 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 ab|rebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 ab^rebg|</div>',
  `${behavior} 20-21 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abr|ebg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abr^ebg|</div>',
  `${behavior} 20-22 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abre|bg</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abre^bg|</div>',
  `${behavior} 20-23 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abreb|g</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abreb^g|</div>',
  `${behavior} 20-24 ltr right word`);

selection_test(
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg|</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="ltr">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg|</div>',
  `${behavior} 20-25 ltr right word`);
}
</script>
